.PHONY: run build test clean swagger migrate

# 应用名称
APP_NAME=admin-nexus-backend

# 运行开发服务器
run:
	go run cmd/main.go

# 编译
build:
	go build -o bin/$(APP_NAME) cmd/main.go

# 运行测试
test:
	go test -v ./...

# 测试覆盖率
test-coverage:
	go test -v -coverprofile=coverage.out ./...
	go tool cover -html=coverage.out -o coverage.html

# 清理
clean:
	rm -rf bin/
	rm -rf logs/
	rm -f coverage.out coverage.html

# 生成 Swagger 文档
swagger:
	swag init -g cmd/main.go -o docs/swagger

# 代码格式化
fmt:
	go fmt ./...

# 代码检查
lint:
	golangci-lint run

# 安装依赖
deps:
	go mod download
	go mod tidy

# 数据库迁移
migrate:
	go run cmd/migrate/main.go

# 初始化数据
seed:
	go run cmd/seed/main.go

# 初始化超级管理员
init-superadmin:
	go run cmd/init_superadmin/main.go

# 检查数据库表
check-tables:
	go run cmd/check_tables/main.go

# 热重载（需要安装 air）
dev:
	air

# Docker 构建
docker-build:
	docker build -t $(APP_NAME):latest .

# Docker 运行
docker-run:
	docker-compose up -d

# Docker 停止
docker-stop:
	docker-compose down

# 帮助
help:
	@echo "可用命令:"
	@echo "  make run            - 运行开发服务器"
	@echo "  make build          - 编译项目"
	@echo "  make test           - 运行测试"
	@echo "  make test-coverage  - 运行测试并生成覆盖率报告"
	@echo "  make clean          - 清理构建文件"
	@echo "  make swagger        - 生成 Swagger 文档"
	@echo "  make fmt            - 格式化代码"
	@echo "  make lint           - 代码检查"
	@echo "  make deps           - 安装依赖"
	@echo "  make migrate        - 数据库迁移"
	@echo "  make seed           - 初始化数据"
	@echo "  make init-superadmin - 初始化超级管理员（用户名: systemop, 密码: Systemop@123）"
	@echo "  make check-tables   - 检查和修复数据库表"
	@echo "  make dev            - 热重载运行（需要 air）"
	@echo "  make docker-build   - Docker 构建"
	@echo "  make docker-run     - Docker 运行"
	@echo "  make docker-stop    - Docker 停止"

